//
//  WYMainController.swift
//  weibo
//
//  Created by 王玉东 on 16/4/6.
//  Copyright © 2016年 wyd. All rights reserved.
//

import UIKit

class WYMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //self.view.backgroundColor = UIColor.redColor()
        
        let tabbar:WYTabBarView = WYTabBarView()
        
        setValue(tabbar, forKey: "tabBar")
        //添加
        addchildViews()
        
        tabbar.centerBtn .addTarget(self, action: "centerClick", forControlEvents: .TouchUpInside)
    
        // Do any additional setup after loading the view.
    }
    
 @objc private  func centerClick() {
    print("点击了中间按钮")
    }
    
    
    func addchildViews() {
    
        addChildViewController(WYHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(WYMessageViewController(), title: "信息", imageName: "tabbar_message_center")
        addChildViewController(WYDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(WYProfileViewController(), title: "我", imageName: "tabbar_profile")

    }
    
    
    
    
    private func addChildViewController(vc: UIViewController,title:String,imageName:String) {
        //创建vc控制器
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes( [NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        let nav = WYBaseNavigationController(rootViewController: vc)
    
        self.addChildViewController(nav)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
